package com.kk.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * the class of spring_security_demo
 *
 * <p>
 * .
 *
 * @author little_lunatic
 * @date 2023-06-14
 */

@Controller
@Slf4j
public class MainController {

//    @GetMapping("/login")
//    public String loginPage() {
//        log.info("login page");
//        return "login";
//    }

    @GetMapping("/index")
    @PreAuthorize("hasAnyRole('USER','ADMIN')")
    public String index() {
        log.info("index page");
        return "index";
    }


    @GetMapping("/admin")
    @PreAuthorize("hasAnyRole('ADMIN')")
    public String printAdmin() {
        log.info("hello admin");
        return "admin";
    }

    @GetMapping("/user")
    @PreAuthorize("hasAnyRole('USER','ADMIN')")
    public String printUser() {
        log.info("hello user");
        return "user";
    }

    /**
     * 找不到页面
     */
    @GetMapping("/404")
    public String notFoundPage() {
        return "/error/404";
    }

    /**
     * 未授权
     */
    @GetMapping("/403")
    public String accessError() {
        return "/error/403";
    }

    /**
     * 服务器错误
     */
    @GetMapping("/500")
    public String internalError() {
        return "/error/500";
    }
}
